package com.jflyfox.component.util;

import java.util.Calendar;

import com.jfinal.log.Log;

public final class DateUtils {
	
	private static Log log = Log.getLog(DateUtils.class);

	/**
	 * 获取年、月、日
	 * 
	 * @param type YEAR或MONTH或DAY
	 * @return
	 */
	public static String getByType(String type) {
		Calendar c = Calendar.getInstance();
		int year = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH) + 1;
		int day = c.get(Calendar.DAY_OF_MONTH);
		
		if ("YEAR".equalsIgnoreCase(type)) {
			return String.valueOf(year);
		} else if ("MONTH".equalsIgnoreCase(type)) {
			return String.valueOf(month);
		} else if ("DAY".equalsIgnoreCase(type)) {
			return String.valueOf(day);
		} else {
			if (log.isWarnEnabled()) {
				log.warn("只支持不分大小写的year、month、day。");
			}
		}
		
		return null;
	}

}
